define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'daohuo/index' + location.search,
                    add_url: 'daohuo/add',
                    edit_url: 'daohuo/edit',
                    del_url: 'daohuo/del',
                    multi_url: 'daohuo/multi',
                    import_url: 'daohuo/import',
                    table: 'yundan',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'dingdan_id', title: __('Dingdan_id')},
                        {field: 'admin_id', title: __('Admin_id')},
                        {field: 'shouhuo_id', title: __('Shouhuo_id')},
                        {field: 'chengyun_id', title: __('Chengyun_id')},
                        {field: 'chepai', title: __('Chepai'), operate: 'LIKE'},
                        {field: 'checi', title: __('Checi'), operate: 'LIKE'},
                        {field: 'start', title: __('Start'), operate: 'LIKE'},
                        {field: 'tidizhi', title: __('Tidizhi'), operate: 'LIKE'},
                        {field: 'desti', title: __('Desti'), operate: 'LIKE'},
                        {field: 'xiedizhi', title: __('Xiedizhi'), operate: 'LIKE'},
                        {field: 'huowu', title: __('Huowu'), operate: 'LIKE'},
                        {field: 'zhongliang', title: __('Zhongliang'), operate:'BETWEEN'},
                        {field: 'tihuoshixian', title: __('Tihuoshixian')},
                        {field: 'daoshixian', title: __('Daoshixian')},
                        {field: 'queren', title: __('Queren')},
                        {field: 'shishou', title: __('Shishou'), operate:'BETWEEN'},
                        {field: 'status', title: __('Status')},
                        {field: 'yuyuetime', title: __('Yuyuetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'linkphone', title: __('Linkphone'), operate: 'LIKE'},
                        {field: 'linkman', title: __('Linkman'), operate: 'LIKE'},
                        {field: 'tihuoshijian', title: __('Tihuoshijian')},
                        {field: 'xiehuoshijian', title: __('Xiehuoshijian')},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});